package com.qiujie.controller;

import com.qiujie.dto.ResponseDTO;
import com.qiujie.entity.DailyMenu;
import com.qiujie.service.DailyMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.sql.Date;

/**
 * 每日食谱控制器
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "每日食谱")
public class DailyMenuController {

    @Autowired
    private DailyMenuService dailyMenuService;

    @PostMapping("/create")
    @ApiOperation("创建每日食谱")
    @PreAuthorize("hasAnyAuthority('dailymenu:create')")
    public ResponseDTO create(@RequestBody DailyMenu dailyMenu) {
        return this.dailyMenuService.create(dailyMenu);
    }

    @PutMapping("/update")
    @ApiOperation("更新每日食谱")
    @PreAuthorize("hasAnyAuthority('dailymenu:update')")
    public ResponseDTO update(@RequestBody DailyMenu dailyMenu) {
        return this.dailyMenuService.update(dailyMenu);
    }

    @GetMapping("/list")
    @ApiOperation("获取食谱列表")
    public ResponseDTO getList() {
        return this.dailyMenuService.getList();
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("获取食谱详情")
    public ResponseDTO getDetail(@PathVariable Integer id) {
        return this.dailyMenuService.getDetail(id);
    }

    @PostMapping("/upload/image")
    @ApiOperation("上传食谱图片")
    @PreAuthorize("hasAnyAuthority('dailymenu:update')")
    public ResponseDTO uploadImage(
            @ApiParam(value = "图片文件", required = true) @RequestParam("file") MultipartFile file) {
        return this.dailyMenuService.uploadImage(file);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除每日食谱")
    public ResponseDTO delete(@PathVariable Integer id) {
        return this.dailyMenuService.delete(id);
    }

} 